﻿#ifndef _OSA_MQUEUE_H_
#define _OSA_MQUEUE_H_

#include <osa_mque.h>
#include <pthread.h>
#include <fcntl.h>
 
#define O_NONBLOCK    04000

struct mqdes
{
	/* reference count and unlinked */
	Uint16 refcount;
	Uint16 unlinked;

	OSA_MqueHndl* mq;
	/* next posix mqueue */
	struct mqdes* next;
};
typedef struct mqdes* OSA_MqdHndl;
 
struct osa_mq_attr
{
	long mq_flags;      /* Message queue flags. */
	long mq_maxmsg;     /* Maximum number of messages. */
	long mq_msgsize;    /* Maximum message size. */
	long mq_curmsgs;    /* Number of messages currently queued. */
};

#ifdef __cplusplus
extern "C" {
#endif

	int     OSA_mqClose(OSA_MqdHndl mqdes);
	int     OSA_mqGetattr(OSA_MqdHndl mqdes, struct osa_mq_attr *mqstat);
	int     OSA_mqNotify(OSA_MqdHndl mqdes, const struct sigevent *notification);
	OSA_MqdHndl   OSA_mqOpen(const char *name, int oflag, ...);
	size_t OSA_mqReceive(OSA_MqdHndl mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio);
	int     OSA_mqSend(OSA_MqdHndl mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio);
	int     OSA_mqSetattr(OSA_MqdHndl                 mqdes,
		const struct osa_mq_attr *mqstat,
	struct osa_mq_attr       *omqstat);
	size_t OSA_mqTimedreceive(OSA_MqdHndl                  mqdes,
		char                  *msg_ptr,
		size_t                 msg_len,
		unsigned              *msg_prio,
		const struct timespec *abs_timeout);
	int     OSA_mqTimedsend(OSA_MqdHndl                  mqdes,
		const char            *msg_ptr,
		size_t                 msg_len,
		unsigned               msg_prio,
		const struct timespec *abs_timeout);

	int     OSA_mqUnlink(const char *name);
	int OSA_mqDelete(OSA_MqdHndl hdl);

#ifdef __cplusplus
}
#endif

#endif
